package top.jiangqiang.qyblog.admin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.jiangqiang.qyblog.common.base.controller.BaseController;
import top.jiangqiang.qyblog.common.base.query.PageResult;
import top.jiangqiang.qyblog.common.base.response.Result;
import top.jiangqiang.qyblog.common.constant.RequestURLConstants;
import top.jiangqiang.qyblog.core.domain.dto.LinkAddDto;
import top.jiangqiang.qyblog.core.domain.dto.LinkUpdateDto;
import top.jiangqiang.qyblog.core.domain.vo.LinkVo;
import top.jiangqiang.qyblog.core.service.ILinkService;

/**
 * @author jiangqiang
 * @date 2022-11-27
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(RequestURLConstants.LINK_CONTROLLER_PREFIX)
@Tag(name = "友情链接接口")
public class LinkController extends BaseController {
    private final ILinkService linkService;

//    @PostMapping("/query")
//    @Operation(summary = "根据条件查询友情链接列表", description = "支持分页，排序等功能")
//    public Result<PageResult<LinkVo>> list(@RequestBody QueryCondition query) {
//        return Result.ok(linkService.findByCondition(query, LinkVo.class));
//    }

    @GetMapping("/{id}")
    @Operation(summary = "查询友情链接详情", description = "查询友情链接详情")
    public Result<LinkVo> get(@PathVariable Long id) {
        return linkService.getLink(id);
    }

    @PostMapping
    @Operation(summary = "新增友情链接", description = "新增一个友情链接")
    public Result<LinkVo> save(@RequestBody LinkAddDto linkAddDto) {
        return linkService.saveLink(linkAddDto);
    }

    @PutMapping
    @Operation(summary = "编辑友情链接", description = "根据id修改一个友情链接")
    public Result<LinkVo> update(@RequestBody LinkUpdateDto linkUpdateDto) {
        return linkService.editLink(linkUpdateDto);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除友情链接", description = "根据id修改一个友情链接")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(linkService.removeById(id));
    }

}
